<?php defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

/* JoomLeague League Management and Prediction Game for Joomla!
 * @version $Id: show_user.tpl.php 1151 2008-06-24 15:07:32Z julienv $
 * @package Joomleague
 * @copyright Copyright (C) 2007  JoomLeague
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see _joomleague_license.txt
 *  
 * Homepage: http://www.joomleague.de
 * Support: htt://www.joomleague.de/forum/
 * 
 * This file is part of JoomLeague.
 *  
 * JoomLeague is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * Please note that the GPL states that any headers in files and
 * Copyright notices as well as credits in headers, source files
 * and output (screens, prints, etc.) can not be removed.
 * You can extend them with your own credits, though...
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * The "GNU General Public License" (GPL) is available at
 * http://www.gnu.org/copyleft/gpl.html.
*/ 

// This template provides three output formats:

// 1.) it is the data output for Flash Chart of users scoring from matchday to match
// 2.) it is the data output for Flash Chart of users Ranking from matchday to match
// 3.) it's a usual joomla content page to display Tippusers information

// check for first output option
if ($jl_func == "showuser_getchartdatascore")
{
  // Calculate Values for Chart Object
  // TODO don not copy data1 stuff to data_1 array, prepare $points for direct use
  $data_1 = array();
  $label = '';
  
  for( $i=1; $i<=count($points); $i++ )
  {
    if ($i <= $round)
    {
      $data_1[] = $points[$i];
    }
    else
    {
      $data_1[] = 0;
    }
    
    if ($label) $label .= ',';
    $label .= $i;
  }

  // Generate RenderCommands for Chart Object

  include( JL_FRONTEND_PATH.'/lib/open-flash-chart/open-flash-chart.php' );
  $g = new graph();

  // backgound color of flash statistic
  $g->bg_colour = $overall_config['bg_colour'];
  // inner background color with gradient
  $g->set_inner_background( $overall_config['inner_bg_gradient_1'], $overall_config['inner_bg_gradient_2'], $overall_config['inner_bg_gradient_orientation'] );

  // data 1
  $g->set_data( $data_1 );
  // first bar
  $g->bar( 50, $overall_config['bar1'], _JL_TABLE_POINTS, 10 );
  
  // x-axis color (color for bottom x-axis, color for inner x-axis)
  $g->x_axis_colour( $overall_config['x_axis_colour'], $overall_config['y_axis_colour_inner'] );
  // y-axis color (color for left y-axis, color for inner y-axis)
  $g->y_axis_colour( $overall_config['y_axis_colour'], $overall_config['x_axis_colour_inner'] );
  // x-axis legend (description, heigt, color)
  if ($overall_config['x_axis_legend']==1) $g->set_x_legend( _JL_MATCHDAY, 14, '#000000' );
  // y-axis legend (description, heigt, color)
  if ($overall_config['y_axis_legend']==1) $g->set_y_legend( _JL_TABLE_POINTS, 14, '#000000' );
  // x-axis labels
  $g->set_x_labels( array( $label ) );
  // x-axis labels style
  $g->set_x_label_style( 10, '#000000', 0, 2, '' );
  // min y-axis value
  $g->set_y_min( 0 );
  // max. y-axis value
  // well, general formula: $givenmaxval - $givenmaxval % $wishedcountofsteps + $wishedcountofsteps
  // if you want no space to top if number is divisibly by $wishedcountofsteps you must not add
  // $wishedcountofsteps ... like:
  // $myset_y_max = (($givenmaxval % $wishedcountofsteps)==0) ? $givenmaxval - $givenmaxval % $wishedcountofsteps : $givenmaxval - $givenmaxval % $wishedcountofsteps + $wishedcountofsteps;
  // $g->set_y_max( $myset_y_max );
  // manygreetz, carsten :-)
  $g->set_y_max( $maxpunkte + 5 - $maxpunkte % 5 );
  // y-axis steps
  $g->y_label_steps( 5 );      
   // tooltip
  $g->set_tool_tip( _JL_TABLE_POINTS.': #val#' );     

  //$g->set_y_legend( 'Punktzahl', 12, '#736AFF' );

  echo  $g->render(); // Method doesn't really render, but it returns a drawlist as multiline text string
  exit();
}

// check for second output option
if ($jl_func == "showuser_getchartdatarank")
{
  // Calculate Values for Chart Object
  // TODO don not copy data1 stuff to data_1 array, prepare $points for direct use
  $data_1 = array();
  $data_2 = array();
  $label = '';
  
  for( $i=1; $i<=count($points); $i++ )
  {
    if ($i <= $round)
    {
      $data_1[] = $ranking[$i];
      $data_2[] = $rankingafterRound[$i];
    }
    else
    {
      $data_1[] = 'null';
      $data_2[] = 'null';
    }

    if ($label) $label .= ',';
    $label .= $i;
  }

  $query = "SELECT COUNT(tm.user_id) 
              FROM #__joomleague_tip_members tm
         LEFT JOIN #__users u ON u.id=tm.user_id 
            WHERE tm.approved=1 AND tm.project_id = ".$joomleague->id;
  $database->setQuery($query);
  $totalusers=$database->loadResult();

  // Generate RenderCommands for Chart Object

  include( JL_FRONTEND_PATH.'/lib/open-flash-chart/open-flash-chart.php' );
  $g = new graph();

  // backgound color of flash statistic
  $g->bg_colour = $overall_config['bg_colour'];
  // inner background color with gradient
  $g->set_inner_background( $overall_config['inner_bg_gradient_1'], $overall_config['inner_bg_gradient_2'], $overall_config['inner_bg_gradient_orientation'] );
  // data 1 - Rank for only this round
  $g->set_data( $data_1 );
  // first line
  $g->line_hollow( $overall_config['line1_strength'], $overall_config['line1_dot_strength'], $overall_config['line1'], _JL_USER_PAGE_MATCHDAY_RANK, 10 );
  // data 2 -Rank for all round until this round
  $g->set_data( $data_2 );
  // first line
  $g->line_hollow( $overall_config['line1_strength'], $overall_config['line1_dot_strength'], $overall_config['line2'], _JL_USER_PAGE_TOTAL_RANK, 10 );
  // x-axis color (color for bottom x-axis, color for inner x-axis)
  $g->x_axis_colour( $overall_config['x_axis_colour'], $overall_config['y_axis_colour_inner'] );
  // y-axis color (color for left y-axis, color for inner y-axis)
  $g->y_axis_colour( $overall_config['y_axis_colour'], $overall_config['x_axis_colour_inner'] );
  // x-axis legend (description, heigt, color)
  if ($overall_config['x_axis_legend']==1) $g->set_x_legend( _JL_MATCHDAY, 14, '#000000' );
  // y-axis legend (description, heigt, color)
  if ($overall_config['y_axis_legend']==1) $g->set_y_legend( _JL_USER_PAGE_RANK, 14, '#000000' );
  // x-axis labels
  $g->set_x_labels( array( $label ) );
  // x-axis labels style
  $g->set_x_label_style( 10, '#000000', 0, 2, '' );
  // min y-axis value
  $g->set_y_max( 1 );
  //$g->set_y_min( $totalusers + 10 - $totalusers % 10 );
  $step=(($totalusers + 20) - ($totalusers % 20)) /20;
  $wishedcountofsteps = (($totalusers % $step)!=0) ? (($totalusers - ($totalusers % $step) + $step ) / $step) : $totalusers / $step;
//  $wishedcountofsteps=19;
//  $myset_y_max = (($totalusers % $wishedcountofsteps)==0) ? $totalusers - $totalusers % $wishedcountofsteps : $totalusers - $totalusers % $wishedcountofsteps + $wishedcountofsteps;
//  $myset_y_max = $totalusers - ($totalusers % $step) + $step;
  $myset_y_max = ($wishedcountofsteps * $step);
//  $myset_y_max = $totalusers;
  $g->set_y_min( $myset_y_max+1 );
  
  // max. y-axis value
  // well, general formula: $givenmaxval - $givenmaxval % $wishedcountofsteps + $wishedcountofsteps
  // if you want no space to top if number is divisibly by $wishedcountofsteps you must not add
  // $wishedcountofsteps ... like:
   
  // $g->set_y_max( $myset_y_max );
  // manygreetz, carsten :-)
  //$g->set_y_max( $totalusers + 10 - $totalusers % 10 );
  // y-axis steps
  $g->y_label_steps( $wishedcountofsteps );      
   // tooltip
  $g->set_tool_tip( _JL_USER_PAGE_RANK.': #val#' );     

  //$g->set_y_legend( 'Punktzahl', 12, '#736AFF' );

  echo  $g->render(); // Method doesn't really render, but it returns a drawlist as multiline text string
  exit();
}

// ELSE (third output option):

  // Show Content of ShowUser Template


?>
<div id="joomleague">
<!-- Header with Project Name-->
<?php if ($showUser_config['show_project_heading'] == "1" OR $overall_config['show_project_heading'] == "1") { ?>
<div class="componentheading" <?php if ($showUser_config['show_print_button'] == "1" OR $overall_config['show_print_button'] == "1") echo 'style="float:left;"';?>><?php echo $htmlHelper->showTitle($joomleague, $overall_config['project_heading_type']); ?></div>
<!-- Druckfunktion -->
<?php if ($showUser_config['show_print_button'] == "1" OR $overall_config['show_print_button'] == "1") {
$htmlHelper->PrintIcon( $row, $params, false, '' );
};?>
<!-- Druckfunktion Ende -->
<?php } ?>
<!-- Header END -->

<!-- Bereichs�berschrift z.B Tabelle, Tippabgabe usw. -->
<table width="100%" class="contentpaneopen">
  <tr>
    <td class="contentheading">
      <?php if ($showUser_config['show_full_name']==1) echo $user->name; else echo $user->username;?> 
<?php
  if ($allowed==1) {
    $htmlHelper->show_edit_icon_tipp();
  }
?>    
    </td>
    <td class="contentheading" align="right"><?php echo $pageNav2; ?></td>
  </tr>
</table>
<!-- Bereichs�berschrift Ende -->

<br />

<!-- Inhalt -->
<table width="96%" align="center" border="0" cellpadding="3" cellspacing="0">
  <tr>
<?php if($showUser_config['show_image_from']>0) {;?>  
    <td valign="top" align="left" width="15%">
<?php 
  if ($showUser_config['show_image_from']==1) {;
      echo '<img src="'.$user_picture.'" border="0" alt="'.$user->name.'" style="max-width:150px;max-height:150px;padding: 5px" />';
      };
  if ($showUser_config['show_image_from']==2) {;
      $database->setQuery(sprintf("SELECT avatar FROM #__comprofiler WHERE user_id = %s", $user->id));
      $cb_user_picture = $database->loadResult(); 
      echo '<img src="'._JOOMLA_JL_LIVE_SITE.'/images/comprofiler/'.$cb_user_picture.'" border="0" style="max-width:150px;max-height:150px;padding: 5px" alt="'.$user->name.'" />';
      } ;     
  if ($showUser_config['show_image_from']==3) {;
      $database->setQuery(sprintf("SELECT avatar FROM #__fb_users WHERE userid = %s", $user->id));
      $fb_user_picture = $database->loadResult();  
      echo '<img src="'._JOOMLA_JL_LIVE_SITE.'/components/com_fireboard/avatars/'.$fb_user_picture.'" border="0" style="max-width:150px;max-height:150px;padding: 5px" alt="'.$user->name.'" />';
      } ;?>    
    </td>
<?php };?>    
    <td valign="top" align="left">
      <table>
        <?php if ($showUser_config['show_register_date']==1) {;?>
        <tr>
          <td><b><?php echo _JL_USER_PAGE_MEMBER_SINCE;?></b></td><td>&nbsp;</td><td><?php echo mosFormatDate($user->registerDate, "%d.%m.%Y",0);?></td>
        </tr>
        <?php };?>
        <?php if ($showUser_config['show_fav_team']==1) {;?>
        <tr>
          <td><b><?php echo _JL_USER_PAGE_FAV_TEAM;?>:</b></td><td>&nbsp;</td><td nowrap="nowrap"><?php echo $fav_team;?></td>
        </tr>
        <?php };?>
        <?php if ($showUser_config['show_slogan']==1) {;?>        
        <tr>
          <td><b><?php echo _JL_USER_PAGE_SLOGAN;?>:</b></td><td>&nbsp;</td><td width="100px"><?php echo $user->slogan;?></td>
        </tr>
        <?php };?>        
        <tr>
        <td>&nbsp;</td>
        </tr>
        <?php if ($showUser_config['show_lasttip']==1) {;?>        
        <tr>
          <td><b><?php echo _JL_USER_PAGE_LAST_TIP;?>:</b></td><td>&nbsp;</td><td><?php echo mosFormatDate($user->lasttip, "%d.%m.%Y", 0);?></td>
        </tr>
        <?php };?>        
        <?php if($joomleague->tip_champ==1){;?>        
        <tr>
          <td><b><?php echo _JL_USER_PAGE_CHAMPTIP;?>:</b></td><td>&nbsp;</td><td nowrap="nowrap">
            <?php
              $thistime=$joomleague->getTimestamp('',1);
              if (($saisonstart < $thistime) || ($my->id == $uid)) {
                 echo $champ_tip;
              } else {
                 if ($champ_tip) echo '--- --- ---'; else echo '&nbsp;';
              }
            ?>
          </td>
        </tr>
        <?php };?>
        <tr>
        <td>&nbsp;</td>
        </tr>
        <!-- <tr>
          <td><b>Tippgemeinschaft:</b></td><td>&nbsp;</td><td>Name der TG</td>
        </tr> -->
      </table>
    </td>
    <td valign="top" align="left">
      <table>
        <?php if ($showUser_config['show_ranking']==1) {;?>      
        <tr>
          <td><b><?php echo _JL_USER_PAGE_RANK;?>:</b></td><td>&nbsp;</td><td nowrap="nowrap"><?php echo (isset($rankingall)) ? $rankingall : '-'; ?>. <?php echo _JL_USER_PAGE_RANK_SHORT;?></td>
        </tr>
        <?php };?>    
        <?php if ($showUser_config['show_totalpoints']==1) {;?>                  
        <tr>
          <td nowrap="nowrap">
          <?php echo '<a href="'.sefRelToAbs(JL_COMPONENT_LINK.'&amp;func=showTipRanking'.'&amp;p='.$joomleague->id.'&amp;mode=all'.JL_ITEMID_SUFFIX).'"><b>'._JL_USER_PAGE_TOTAL_POINTS.':</b></a>';?></td>
        <td>&nbsp;</td><td><?php echo (isset($pointsall)) ? $pointsall : '-'; ?></td>
        </tr>
        <?php };?>      
        <?php if ($showUser_config['show_lastpoints']==1) {;?>            
        <tr>
          <td nowrap="nowrap">
          <?php echo '<a href="'.sefRelToAbs(JL_COMPONENT_LINK.'&amp;func=showTipRanking&amp;'.'&amp;p='.$joomleague->id.JL_ITEMID_SUFFIX).'"><b>'._JL_USER_PAGE_LAST_POINTS.':</b></a>';?></td>
          <td>&nbsp;</td><td><?php echo (isset($lasttipp)) ? $lasttipp : '-'; ?></td>
        </tr>
        <?php };?>  
        <?php if ($showUser_config['show_counttipps']==1) {;?>                    
        <tr>
          <td><b><?php echo _JL_USER_PAGE_COUNT_TIPS;?>:</b></td><td>&nbsp;</td><td><?php echo (isset($tippCount)) ? $tippCount : '-'; ?></td>
        </tr>
        <?php };?>   
        <?php if ($showUser_config['show_averagepoints']==1) {;?>             
        <tr>
          <td><b><?php echo _JL_USER_PAGE_AVG_POINTS;?>:</b></td><td>&nbsp;</td><td><?php if (isset($tippCount) && $tippCount>0) echo number_format(round($pointsall/$tippCount,2),2); else echo number_format(0,2); ?></td>
        </tr>
        <?php };?>
        <?php if ($showUser_config['show_toptipps']==1) {;?>                
        <tr>
          <td nowrap="nowrap"><b><?php echo _JL_USER_PAGE_TOP_TIPS;?>:</b></td><td>&nbsp;</td><td nowrap="nowrap"><?php echo (isset($hitsCount)) ? $hitsCount : '-'; ?> <?php if (isset($tippCount)) if ($tippCount>0) echo '('.round($hitsCount*100/$tippCount,2).'%)'; else echo '('.number_format(0,2).'%)'; ?></td>
        </tr> 
        <?php };?>    
        <?php if ($showUser_config['show_difftipps']==1) {;?>              
        <tr>
          <td nowrap="nowrap"><b><?php echo _JL_USER_PAGE_CORRECT_DIFF;?>:</b></td><td>&nbsp;</td><td nowrap="nowrap"><?php echo (isset($diffCount)) ? $diffCount : '-'; ?> <?php if (isset($diffCount)) if ($tippCount>0) echo '('.round($diffCount*100/$tippCount,2).'%)'; else echo '('.number_format(0,2).'%)'; ?></td>
        </tr>   
        <?php };?>
        <?php if ($showUser_config['show_tendtipps']==1) {;?>                
        <tr>
          <td nowrap="nowrap"><b><?php echo _JL_USER_PAGE_CORRECT_TEND;?>:</b></td><td>&nbsp;</td><td nowrap="nowrap"><?php echo (isset($tendCount)) ? $tendCount : '-'; ?> <?php if (isset($tendCount)) if ($tippCount>0) echo '('.round($tendCount*100/$tippCount,2).'%)'; else echo '('.number_format(0,2).'%)'; ?></td>
        </tr> 
        <?php };?>                                          
        <tr>
        <td>&nbsp;</td>
        </tr>
        <?php if ($showUser_config['show_form']==1) {;?>        
        <tr>
          <td><b><?php echo _JL_USER_PAGE_TIP_FORM;?>:</b></td><td>&nbsp;</td><td>
          <img src="<?php echo JL_TEMPLATE_FOLDERS_URL;?>/images/up.png" alt="" />
          <img src="<?php echo JL_TEMPLATE_FOLDERS_URL;?>/images/same.png" alt="" />
          <img src="<?php echo JL_TEMPLATE_FOLDERS_URL;?>/images/down.png" alt="" /></td>
        </tr>  
        <?php };?>                
      </table>
    </td>    
  </tr>
</table>
<!-- Inhalt Ende-->

<br />

<!-- Flash Statistik Start -->
<?php if ($showUser_config['show_flash_statistic_points']==1) {;?>
<table width="96%" align="center" border="0" cellpadding="3" cellspacing="0">
	<tr class="sectiontableheader">
    <td><?php echo _JL_USER_PAGE_SEASON_POINTS ;?></td>
  </tr>
  <tr>
    <td align="center">
      <?php
      // put OFC object to JL page 
      // item ID is required, cause some SEF modules need it to verify a correct JOOMLA request
      $htmlHelper->open_flash_chart_object( '100%', 250, _JOOMLA_JL_LIVE_SITE."/".str_replace('&amp;', '%26', JL_COMPONENT_LINK.JL_ITEMID_SUFFIX)."%26func=showUser_GetChartDataScore%26p=".$p."%26uid=".$uid );
      ?>
    </td>
  </tr>  
</table>

<br />
<?php } ;?>
<?php if ($showUser_config['show_flash_statistic_ranks']==1) {;?>
<table width="96%" align="center" border="0" cellpadding="3" cellspacing="0">
	<tr class="sectiontableheader">
    <td><?php echo _JL_USER_PAGE_SEASON_RANKS ;?></td>
  </tr>
  <tr>
    <td align="center">
      <?php
      // put OFC object to JL page
      $htmlHelper->open_flash_chart_object( '100%', 250, _JOOMLA_JL_LIVE_SITE."/".str_replace('&amp;', '%26', JL_COMPONENT_LINK.JL_ITEMID_SUFFIX)."%26func=showUser_GetChartDataRank%26p=".$p."%26uid=".$uid );
      ?>
    </td>
  </tr>  
</table>
<?php } ;?>
<!-- Flash Statistik ENDE -->

<!-- Print Button START -->
<?php if ($showUser_config['show_back_button'] > 0 OR $overall_config['show_back_button'] > 0) {;?>
<?php if ($showUser_config['show_back_button'] == "1" OR $overall_config['show_back_button'] == "1") echo '<div align="left">'; else echo '<div align="right">';?>
<?php
$params = & new mosParameters( '' );
$params->def( 'back_button', true );
$params->def( 'popup', false );
mosHTML::BackButton( $params );
  echo "</div>";
};?>
<!-- Print Button END -->
</div>
